define(["jquery", "easy-admin"], function ($, ea) {

    var init = {
        table_elem: '#currentTable',
        table_render_id: 'currentTableRenderId',
        index_url: 'demo.order/index',
        add_url: 'demo.order/add',
        edit_url: 'demo.order/edit',
        delete_url: 'demo.order/delete',
        export_url: 'demo.order/export',
        modify_url: 'demo.order/modify',
    };

    var Controller = {

        index: function () {
            ea.table.render({
                init: init,
                cols: [[
                    {type: 'checkbox'},
                    {field: 'id',search:false, title: '主键id'},
                    {field: 'order_no', title: '订单编号'},
                    {field: 'goods.good_name', title: '商品名称'},
                    {field: 'users.nickname', title: '用户昵称'},
                    {field: 'goods_nums', search:false, title: '购买数量'},
                    {field: 'goods_price', search:false, title: '商品单价'},
                    {field: 'goods_total', search:false, title: '商品总价'},
                    {
                        field: 'order_type', title: '订单分类', templet: function (d) {
                            if (d.order_type == 0) {
                                return '<span class="layui-badge layui-bg-green">分销</span>';
                            }
                            if (d.order_type == 1) {
                                return '<span class="layui-badge layui-bg-green">核销</span>';
                            }
                            if (d.order_type == 2) {
                                return '<span class="layui-badge layui-bg-green">拼团</span>';
                            }
                            if (d.order_type == 3) {
                                return '<span class="layui-badge layui-bg-green">砍价</span>';
                            }
                            if (d.order_type == 4) {
                                return '<span class="layui-badge layui-bg-green">拼团成员</span>';
                            }
                            if (d.order_type == 5) {
                                return '<span class="layui-badge layui-bg-green">普通商户</span>';
                            }
                        }
                        , search: 'select'
                        , selectList: {0: '分销', 1: '核销', 2: '拼团', 3: '砍价', 4: '拼团成员', 5: '普通商户'}
                    },
                    {
                        field: 'order_status', title: '审核状态', templet: function (d) {
                            if (d.order_status == 0) {
                                return '<span class="layui-badge layui-bg-orange">待支付</span>';
                            }
                            if (d.order_status == 1) {
                                return '<span class="layui-badge layui-bg-green">已支付</span>';
                            }
                            if (d.order_status == 2) {
                                return '<span class="layui-badge layui-bg-orange">揽件中</span>';
                            }
                            if (d.order_status == 3) {
                                return '<span class="layui-badge layui-bg-orange">已发货</span>';
                            }
                            if (d.order_status == 4) {
                                return '<span class="layui-badge layui-bg-orange">已完成</span>';
                            }
                            if (d.order_status == 5) {
                                return '<span style="background-color: red" class="layui-badge">退款中</span>';
                            }
                            if (d.order_status == 6) {
                                return '<span style="background-color: red" class="layui-badge">已退款</span>';
                            }
                            if (d.order_status == 7) {
                                return '<span style="background-color: red" class="layui-badge">支付失败</span>';
                            }
                            if (d.order_status == 8) {
                                return '<span class="layui-badge layui-bg-orange">待核销</span>';
                            }
                            if (d.order_status == 9) {
                                return '<span class="layui-badge layui-bg-orange">已核销</span>';
                            }
                        }
                        , search: 'select'
                        , selectList: {0: '待支付', 1: '已支付', 2: '揽件中', 3: '已发货', 4: '已完成',
                            5: '退款中', 6: '已退款', 7: '支付失败', 8: '待核销',  9: '已核销'}
                    },
                    {field: 'create_time', title: '创建时间'},
                    {width: 250, title: '操作', templet: ea.table.tool},
                ]],
            });

            ea.listen();
        },

        add: function () {
            ea.listen();
        },
        edit: function () {
            ea.listen();
        },
    };
    return Controller;
});